import { Select } from "antd"
import { useDispatch, useSelector } from "react-redux"
import { useEffect } from "react"
import { getChannels } from "@/store/actions"
const { Option } = Select

const Channel = ({ value, onChange, width = 400 }) => {
  const dispatch = useDispatch()
  const { channels } = useSelector((state) => state.article)

  useEffect(() => {
    dispatch(getChannels())
  }, [dispatch])

  return (
    <Select placeholder="请选择文章频道" style={{ width }} value={value} onChange={onChange}>
      {channels.map((item) => (
        <Option key={item.id} value={item.id}>
          {item.name}
        </Option>
      ))}
    </Select>
  )
}

export default Channel
